home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Libraries
/
SpriteEngine
/
SE RectBounce
/
SpriteHanders.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-11
|
2KB
|
76 lines
#include "SpriteTools.h"
// SpriteTools.h includes SpriteHandlers.h
/*** Custom handlers - application dependent ***
Edit this as necessary. It should always include the following three routines:
MoveSprite: move the sprite
HitSprite: handle collisions between two sprites
InitSprites: Load all faces and create initial sprites
***/
GrafPtr firstFace, secondFace, thirdFace;
void MoveSprite(SpritePtr theSprite)
{
theSprite->position.h += theSprite->speed.h;
theSprite->position.v += theSprite->speed.v;
KeepOnScreen(theSprite);
} /*MoveSprite*/
void HitSprite(SpritePtr theSprite, SpritePtr anotherSprite)
{
short tempSpeed;
if (RectSeparate(theSprite, anotherSprite) >= 2) // 2 or 3: horizontal, otherwise vertical
{
tempSpeed = theSprite->speed.h;
theSprite->speed.h = anotherSprite->speed.h;
anotherSprite->speed.h = tempSpeed;
}
else
{
tempSpeed = theSprite->speed.v;
theSprite->speed.v = anotherSprite->speed.v;
anotherSprite->speed.v = tempSpeed;
}
} /*HitSprite*/
void InitSprites()
{
SpritePtr theSprite;
/*Load all pictures*/
firstFace = LoadFaceFromCicn(128); /*cicn resource #128.*/
secondFace = LoadFaceFromCicn(129); /*cicn resource #129.*/
thirdFace = LoadFaceFromCicn(130); /*cicn resource #130.*/
/*Create sprites*/
theSprite = NewSprite();
theSprite->face = firstFace;
SetPt(&theSprite->position, 100, 100);
SetPt(&theSprite->speed, Rand(7)-3, Rand(7)-3);
theSprite = NewSprite();
theSprite->face = secondFace;
SetPt(&theSprite->position, 50, 50);
SetPt(&theSprite->speed, Rand(7)-3, Rand(7)-3);
theSprite = NewSprite();
theSprite->face = thirdFace;
SetPt(&theSprite->position, 150, 150);
SetPt(&theSprite->speed, Rand(7)-3, Rand(7)-3);
} /*InitSprites*/